package com.zxjbyte.yiyi.framework.mybatis.util;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author zhangxingjia
 * @Date 2023/3/15 11:52
 * @Version: 1.0
 */
public class MybatisUtil {

    /**
     * 将拦截器添加到MybatisPlusInterceptor中指定位置
     *
     * @param interceptor 链
     * @param inner 拦截器
     * @param index 位置
     */
    public static void addInterceptor(MybatisPlusInterceptor interceptor, InnerInterceptor inner, int index) {
        List<InnerInterceptor> inners = new ArrayList<>(interceptor.getInterceptors());
        inners.add(index, inner);
        interceptor.setInterceptors(inners);
    }
}
